<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2023-01-06 13:51:18
 * @LastEditors: CNN 969682281@qq.com
 * @LastEditTime: 2024-01-19 16:39:02
 * @FilePath: \mould\src\views\pages\Supervision\deviationTrend.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->


<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->

      <div class="mechanism_nav app-container-search">
        <el-form ref="form" :model="getList" label-width="110px">
          <el-row :gutter="20">
            <el-col :span="6"
              ><el-form-item label="项目名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.fprojectid"
                  placeholder="所有项目"
                  @change="selectProject"
                >
                  <el-option
                    v-for="v in projectsObj"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="标段名称：">
                <el-select
                  class="selectBhz"
                  v-model="getList.fCompanyid"
                  placeholder="所有标段"
                  @change="selectTender"
                >
                  <el-option
                    v-for="v in tendersObj"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6"
              ><el-form-item label="拌和站：">
                <el-select
                  class="selectBhz"
                  v-model="getList.stationId"
                  placeholder="拌合站查询"
                  @change="selectStation"
                >
                  <el-option
                    v-for="v in bhzDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select> </el-form-item
            ></el-col>
            <el-col :span="6">
              <el-form-item label="拌和机：">
                <el-select
                  class="selectBhz"
                  v-model="getList.machineId"
                  placeholder="拌合机查询"
                >
                  <el-option
                    v-for="v in bhjDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="出料时间：">
                <el-date-picker
                  :picker-options="pickerOptions"
                  value-format="yyyy-MM-dd"
                  @change="selectTime"
                  v-model="timeDuring"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="预警等级：">
                <el-select
                  class="selectBhz"
                  v-model="getList.enCode"
                  placeholder="预警等级"
                >
                  <el-option
                    v-for="v in djDataList"
                    :key="v.fItemName"
                    :label="v.fItemName"
                    :value="v.fItemValue"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col
              :span="6"
              class="searchBtn"
              style="text-align: right; display: flex; justify-content: end"
            >
              <el-form-item>
                <el-button
                  type="primary"
                  :loading="editLoading"
                  @click="yj_searchForm(getList)"
                  >查询</el-button
                >
                <el-button @click="reset">重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <!-- 表格 -->
      <div class="text_table" style="flex: 1">
        <div class="" style="width: 100%; height: 100%">
          <myCharts
            :aggregateData="aggregateData"
            v-loading="chartsLoading"
            element-loading-text="拼命加载中"
            element-loading-spinner="el-icon-loading"
            element-loading-background="rgba(0, 0, 0, 0.3)"
            :time1="this.timeDuring[0]"
            :time2="this.timeDuring[1]"
            :checkType="checkType"
            :commonData="tableData"
            :StationWarnData="StationWarnData"
            :enCode="getList.enCode"
            @clickLegend="clickLegend"
          >
          </myCharts>
        </div>
      </div>
    </div>
  </div>
</template>
  
<script>
// import vDatePicker from "@/components/public/v-DatePicker";
import actions from "@/actions";

const typeOptions = [
  { name: "水", label: "0" },
  { name: "水泥1", label: "1" },
  { name: "水泥2", label: "2" },
  { name: "骨料1", label: "3" },
  { name: "骨料2", label: "4" },
  { name: "骨料3", label: "5" },
  { name: "骨料4", label: "6" },
  { name: "骨料5", label: "7" },
  { name: "矿粉", label: '"8' },
  { name: "粉煤灰", label: "9" },
  { name: "外加剂1", label: "10" },
  { name: "外加剂2", label: "11" },
];

// const typeOptions = ['水', '水泥1', '水泥2', '骨料1', '骨料2', '骨料3', '骨料4', '骨料5', '矿粉', '粉煤灰', '外加剂1', '外加剂2'];
import tree from "@/components/public/el-trees"; //左侧机构树
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
// import selects from "@/components/public/el-select.vue"
import myCharts from "@/components/public/deviationTrendCharts";

import {
  getCensusList2, //主页面列表接口
  getStationmachineByfMachineid,
  getStationWarnByCompanyId,
  getMachineListByStationId, //拌合机
  getStationmachineList, //拌合站列表
} from "@/api/request.js";

export default {
  name: "deviationTrend",
  data() {
    return {
      name: "deviationTrend", //按钮配置页面代号
      // yj_view: null,//查看按钮是否显示
      falgId: null,
      projectsObj: [], //项目名
      tendersObj: [],
      editLoading: false,
      timeDuring: [],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      formData: {}, //新增编辑向后台传递对象

      level: [],
      bhjDataList: [], //拌合机
      bhzDataList: [], //拌合站
      djDataList: [
        //     {
        //     fItemName: "正常",
        //     fItemValue: "0"
        // },
        {
          fItemName: "初级",
          fItemValue: "1",
        },
        {
          fItemName: "中级",
          fItemValue: "2",
        },
        {
          fItemName: "高级",
          fItemValue: "3",
        },
      ],
      timeDuring: "", //主页面日期筛选绑定值
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      // 列表给后端传参
      getList: {
        endDates: "",
        fCheckStatus: "",
        fCloseoperation: "",
        fCompanyid: "",
        fprojectid: "",
        machineId: "",
        modelType: "",
        page: 1,
        pageSize: 15,
        startDates: "",
        stationId: "",
        strengthgrade: "",
        userId: "",
        warningLevel: "",
      },

      checkData: [], //树状图默认选中id
      userInfo: {}, //登录用户

      tableData: [],
      StationWarnData: [],
      // checkType: ['1',  '3', '4', '5', '6',"7",  '9', '10',"11"],

      // checkType: ['水泥1', '骨料1', '骨料2', '骨料3', '骨料4', '骨料5', '粉煤灰', '外加剂1', '外加剂2'],
      checkType: {
        全选: false,
        全不选: false,
        水: false,
        水泥1: true,
        水泥2: false,
        骨料1: true,
        骨料2: true,
        骨料3: true,
        骨料4: true,
        骨料5: true,
        矿粉: false,
        粉煤灰: true,
        外加剂1: true,
        外加剂2: true,
      },
      // checkType: [
      //     'F_Cement1ActualValue', 'F_Aggregate1ActualValue', 'F_Aggregate2ActualValue', 'F_Aggregate3ActualValue', 'F_Aggregate4ActualValue', 'F_Aggregate5ActualValue', 'F_OreActualValue', 'F_Admixture1ActualValue', 'F_Admixture2ActualValue'
      // ],

      types: typeOptions,
      chartsLoading: true,
      aggregateData: [],
      token: null,
    };
  },
  components: {
    // vDatePicker, //时间选择器
    tree, //左侧组织机构数
    elBreadcrumb, //面包屑
    myCharts,
  },
  mounted() {
    actions.onGlobalStateChange((state, prev) => {
      this.userInfo = prev.currentUser;
      var data = prev.currentUser.projects;
      this.token = prev.token;
      this.projectsObj = [
        {
          fItemName: "所有项目",
          fItemValue: "",
        },
      ];
      data.map((item) => {
        this.projectsObj.push({
          fItemName: item.projectName,
          fItemValue: item.projectId,
        });
      });
    }, true);
    this.getDate();
  },

  methods: {
    selectProject(e) {
      this.falgId = e;
      this.tendersObj = [];
      this.bhzDataList = [];
      this.getList.fCompanyid = "";
      this.getList.stationId = "";
      this.getList.machineId = "";
      this.bhjDataList = [];
      // console.log(e);
      this.getTender(e,1);
    },
    async getTender(e,num) {
      await this.$http(
        " http://172.18.5.31:8300/IOTManagement/Base/Company/getGXJLBaseCompanyList.do?projectId=" +
          e,
        {
          headers: {
            "Content-Type": "application/json",
            Authorization: localStorage.getItem("access_token"),
          },
        }
      ).then((res) => {
        if (res.status == 200) {
          var data = res.data.data.GXCompanyList;
          this.tendersObj = [];
          if (data.length == 1) {
            data.map((item) => {
              this.tendersObj.push({
                fItemName: item.sectionName,
                fItemValue: item.sectionId,
              });
            });
            this.getList.fCompanyid = data[0].sectionId;
          } else {
            this.tendersObj = [
              {
                fItemName: "所有标段",
                fItemValue: "",
              },
            ];
            data.map((item) => {
              this.tendersObj.push({
                fItemName: item.sectionName,
                fItemValue: item.sectionId,
              });
            });
          }

          if (num == 0) {
            // num==0 调列表；num==1 不调
            this.yj_searchForm(this.getList);
          }
        }
      });
    },
    selectTender(e) {
      this.falgId = e;

      this.getList.stationId = "";

      this.getList.machineId = "";
      this.bhjDataList = [];
      this.bhzDataList = [];
      // 获取拌合站
      this.mixingPlantList(0, this.getList);
    },
    selectStation(e) {
      this.getList.machineId = "";
      this.bhjDataList = [];
      this.getbhjDataMethods(e);
    },
    // 重置按钮
    reset() {
      this.timeDuring = [];
      this.getList = {
        endDates: "",
        fCheckStatus: "",
        fCloseoperation: "",
        fCompanyid: "",
        fprojectid: "",
        machineId: "",
        modelType: "",
        page: 1,
        pageSize: 15,
        startDates: "",
        stationId: "",
        strengthgrade: "",
        userId: "",
        warningLevel: "",
      };
    },

    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      this.chartsLoading = true;

      window.sessionStorage.setItem("GxEmbedded_getList", JSON.stringify(data));
      var id;
      if (data.fCompanyid != "") {
        id = data.fCompanyid;
      } else {
        id = data.fprojectid;
      }
      var sc = {
        companyId: id, // 施工标段id
        startDates: data.startDates, // 开始时间
        endDates: data.endDates, // 截至时间
        machineId: data.machineId, // 拌和机编号
        stationId: data.stationId, // 拌和站编号
        enCode: "",
      };

      if (data.machineId != "") {
        getStationmachineByfMachineid({ machineId: data.machineId })
          .then((res1) => {
            if (res1.errcode == 0) {
              this.aggregateData = [
                res1.data.yjQmpMsStationmachine.fParm1,
                res1.data.yjQmpMsStationmachine.fParm2,
                res1.data.yjQmpMsStationmachine.fParm3,
                res1.data.yjQmpMsStationmachine.fParm4,
                res1.data.yjQmpMsStationmachine.fParm5,
              ];

              getCensusList2(sc)
                .then((res) => {
                  if (res.errcode == 0) {
                    var that = this;
                    that.listLoading = false;
                    this.chartsLoading = false;

                    that.tableData = {
                      data: res.data.censusList2,
                      type: this.checkType,
                    };
                  } else {
                    this.chartsLoading = false;

                    this.$message.error(res.msg);
                    return false;
                  }
                })
                .catch((error) => {
                  console.log(error);
                });
            } else {
              this.$message.error(res1.msg);
              return false;
            }
          })
          .catch((error) => {
            console.log(error);
          });
      } else {
        if (JSON.parse(sessionStorage.getItem("GxEmbedded_checkData"))) {
          var checkObj = JSON.parse(sessionStorage.getItem("GxEmbedded_checkData"));
          if (
            checkObj.外加剂1 == true &&
            checkObj.外加剂2 == true &&
            checkObj.水 == true &&
            checkObj.水泥1 == true &&
            checkObj.水泥2 == true &&
            checkObj.矿粉 == true &&
            checkObj.粉煤灰 == true &&
            checkObj.骨料1 == true &&
            checkObj.骨料2 == true &&
            checkObj.骨料3 == true &&
            checkObj.骨料4 == true &&
            checkObj.骨料5 == true
          ) {
            checkObj.全选 = true;
            checkObj.全不选 = false;
          } else if (
            checkObj.外加剂1 == false &&
            checkObj.外加剂2 == false &&
            checkObj.水 == false &&
            checkObj.水泥1 == false &&
            checkObj.水泥2 == false &&
            checkObj.矿粉 == false &&
            checkObj.粉煤灰 == false &&
            checkObj.骨料1 == false &&
            checkObj.骨料2 == false &&
            checkObj.骨料3 == false &&
            checkObj.骨料4 == false &&
            checkObj.骨料5 == false
          ) {
            checkObj.全选 = false;
            checkObj.全不选 = true;
          } else {
            checkObj.全选 = false;
            checkObj.全不选 = false;
          }
          this.checkType = checkObj;
          // this.checkType = JSON.parse(sessionStorage.getItem("GxEmbedded_checkData"));
        } else {
          this.checkType = {
            全选: false,
            全不选: false,

            水: false,
            水泥1: true,
            水泥2: false,
            骨料1: true,
            骨料2: true,
            骨料3: true,
            骨料4: true,
            骨料5: true,
            矿粉: false,
            粉煤灰: true,
            外加剂1: true,
            外加剂2: true,
          };
        }

        this.aggregateData = ["骨料1", "骨料2", "骨料3", "骨料4", "骨料5"];

        getCensusList2(data)
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.listLoading = false;
              this.chartsLoading = false;

              that.tableData = {
                data: res.data.censusList2,
                type: this.checkType,
              };
            } else {
              this.chartsLoading = false;

              this.$message.error(res.msg);
              return false;
            }
          })
          .catch((error) => {
            console.log(error);
          });
      }
    },
    getStationWarn(data) {
      getStationWarnByCompanyId(data)
        .then((res) => {
          if (res.errcode == 0) {
            console.log(res);
            var that = this;
            that.listLoading = false;
            var list = res.data.yjQmpMsStationwarn;
            this.StationWarnData = [
              {
                name: "1",
                water: list.fWaterwarn1, //水
                cement: list.fCementwarn1, //水泥
                aggregate: list.fAggregatewarn1, //骨料(%)
                flyash: list.fFlyashwarn1, //粉煤灰
                oredesign: list.fGgbswarn1, //矿粉
                admixture: list.fAdmixture1, //外加剂
                examine: list.fExamine1, //闭合流程
              },
              {
                name: "2",
                water: list.fWaterwarn2, //水
                cement: list.fCementwarn2, //水泥
                aggregate: list.fAggregatewarn2, //骨料(%)
                flyash: list.fFlyashwarn2, //粉煤灰
                oredesign: list.fGgbswarn2, //矿粉
                admixture: list.fAdmixture2, //外加剂
                examine: list.fExamine2, //闭合流程
              },
              {
                name: "3",
                water: list.fWaterwarn3, //水
                cement: list.fCementwarn3, //水泥
                aggregate: list.fAggregatewarn3, //骨料(%)
                flyash: list.fFlyashwarn3, //粉煤灰
                oredesign: list.fGgbswarn3, //矿粉
                admixture: list.fAdmixture3, //外加剂
                examine: list.fExamine3, //闭合流程
              },
            ];
            // that.tableData = that.tranListToTreeDatas(res.data.yjQmpMsStationwarn)
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 获取拌合站数据
    mixingPlantList(num, datas) {
      var data = {
        companyId: datas.fCompanyid, // 施工标段id
        modelType: num, // 类型
        stationType: "1", // 拌合站类型
      };
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;
            this.bhzDataList = [
              {
                fItemName: "所有拌和站",
                fItemValue: "",
              },
            ];

            arr.map((item) => {
              this.bhzDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    getbhjDataMethods(data) {
      getMachineListByStationId({ stationId: data })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            this.bhjDataList = [
              {
                fItemName: "所有拌和机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
            console.log("tttt", this.bhjDataList);
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    clickLegend(e) {
      this.checkType = e;
      window.sessionStorage.setItem("GxEmbedded_checkData", JSON.stringify(e));
    },
    checkChange(e) {
      console.log(e);
      window.sessionStorage.setItem("GxEmbedded_checkData", JSON.stringify(e));
      this.yj_searchForm(this.getList);
    },
    selectTime(e) {
      if (e[0] != "" && e[1] != "") {
        this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
        this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
        this.xlsxName = e[0] + "至" + e[1] + "混凝土拌和站记录数据";
      } else {
        this.getList.startDates = ""; // 开始时间
        this.getList.endDates = ""; // 截至时间
        this.xlsxName = "混凝土拌和站记录数据";
      }
      this.yj_searchForm(this.getList);
    },

    getDate() {
      if (JSON.parse(sessionStorage.getItem("GxEmbedded_getList"))) {
        this.getList = JSON.parse(sessionStorage.getItem("GxEmbedded_getList"));
        if (this.getList.fprojectid != "") {
          this.getTender(this.getList.fprojectid,0);
        } else {
          this.getList.fprojectid = this.projectsObj[1].fItemValue;
          this.getTender(this.getList.fprojectid,0);
        }
        if (this.getList.fCompanyid != "" && this.getList.fCompanyid != null) {
          this.mixingPlantList(0, this.getList);
        }

        if (this.getList.stationId != "" && this.getList.stationId != null) {
          this.getbhjDataMethods(this.getList.stationId);
        }

        if (this.getList.startDates == "" || this.getList.startDates == null) {
          this.getList.startDates = this.common.getDay(-90) + " " + "00:00:00"; // 开始时间
          this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        }
        this.timeDuring = [this.getList.startDates, this.getList.endDates];
        this.xlsxName =
          this.getList.startDates +
          "至" +
          this.getList.endDates +
          "混凝土拌和站记录数据";
      } else {
        this.getList.startDates = this.common.getDay(-90) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.getList.fprojectid = this.projectsObj[1].fItemValue;
        this.getTender(this.getList.fprojectid,0);
        this.timeDuring = [
          this.common.getDay(-90) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
        this.xlsxName =
          this.common.getDay(-90) +
          "至" +
          this.common.getDay(0) +
          " " +
          "23:59:59" +
          "混凝土拌和站记录数据";
      }
    },
  },
};
</script>
  
<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

.materialCharts {
  height: calc(100% - 110px);
  width: 100%;
}

.selectcheckbox {
  margin-left: 15px;
  height: 35px;
  margin-top: -5px;
}
</style>
